﻿<?php
include_once("../initial.php");
include_once("../driver/drive.php");
include_once("../driver/tableLocation.php");
include_once("../global/global_function.php");
class deviceRHandle
{
    public function get_all_data($orderby="", $limit="")
    {
        $tablename = tableLocation::deviceTable();
        $sql = "select * from $tablename $orderby $limit";
        return drive::get_all_rows($sql);
    }
    public function get_device_num($array)
    {
        $tablename = tableLocation::deviceTable();
        $sql = get_select_sql($tablename, "count(*)", $array);
        $result = drive::get_one_value($sql);
        return $result;
    }
    public function get_some_data($array, $orderby='', $limit='')
    {
        $tablename = tableLocation::deviceTable();
        $sql = "select * from $tablename where ";
        $first=0;
        foreach($array as $key=>$value)
        {
            if($first==0)
            {
                $sql .= "`$key`='$value' ";
                $first=1;
            }
            else
            {
                $sql .= "and `$key`='$value'";
            }
        }
        $sql .= " $orderby $limit";
        return drive::get_all_rows($sql);
    }
    public function get_device_pictures($array, $orderby='', $limit='')
    {
    		$tablename = tableLocation::devicePictureTable();
        $sql = "select * from $tablename where ";
        $first=0;
        foreach($array as $key=>$value)
        {
            if($first==0)
            {
                $sql .= "`$key`='$value' ";
                $first=1;
            }
            else
            {
                $sql .= "and `$key`='$value'";
            }
        }
        $sql .= " $orderby $limit";
        return drive::get_all_rows($sql);
    }
    public function get_device_course_number($conditionArray)
    {
        $tablename = tableLocation::deviceCourseTable();
        $sql = get_select_sql($tablename, "count(*)", $conditionArray);
        $result = drive::get_one_value($sql);
        return $result;
    }
    
		public function get_device_courses($conditionArray, $orderby='', $limit='')
		{
				$tablename = tableLocation::deviceCourseTable();
        $sql = "SELECT * FROM $tablename WHERE ";
        $first=0;
        foreach($conditionArray as $key=>$value)
        {
            if($first==0)
            {
                $sql .= " `$key`='$value' ";
                $first=1;
            }
            else
            {
                $sql .= "and `$key`='$value'";
            }
        }
        $sql .= " $orderby $limit";
        //echo $sql;
        return drive::get_all_rows($sql);
		}
		public function searchDevice($keyword, $limit='')
    {
    		$table = tableLocation::deviceTable();
    		$sql = "select * from $table where barcode like '%$keyword%' or name like '%$keyword%' order by id desc $limit";
    		return drive::get_all_rows($sql);
    }
}
?>